home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / agrep / re.h < prev    next >
Text File  |  1994-08-01  |  3KB  |  130 lines

  1. /*************************************************************
  2.  *                                 *
  3.  *     Macros defining special characters.             *
  4.  *                                 *
  5.  *************************************************************/
  6.  
  7. #define NUL        '\0'
  8. #define ASCII_MIN   '\001'
  9. #define ASCII_MAX   '\177'
  10.  
  11. /*************************************************************
  12.  *                                 *
  13.  *     Macros defining lexical categories.             *
  14.  *                                 *
  15.  *************************************************************/
  16.  
  17. #define C_LIT    0   /* individual character literal */
  18. #define C_SET    1   /* character set literal        */
  19.  
  20. #define EOS        0    /* end-of-string */
  21. #define LITERAL        1
  22. #define OPSTAR        2
  23. #define OPALT        3
  24. #define OPOPT        4
  25. #define OPCAT        5
  26. #define LPAREN        6
  27. #define RPAREN        7
  28.  
  29. /*************************************************************
  30.  *                                 *
  31.  *     Macros for manipulating syntax tree nodes.         *
  32.  *                                 *
  33.  *************************************************************/
  34.  
  35. #define lit_type(x)    (x->l_type)
  36. #define lit_pos(x)    (x->pos)
  37. #define lit_char(x)    ((x->val).c)
  38. #define lit_cset(x)    ((x->val).cset)
  39.  
  40. #define tok_type(x)    (x->type)
  41. #define tok_val(x)    (x->val)
  42. #define tok_op(x)       (x->val->op)
  43. #define tok_lit(x)    ((x->val->refs).lit)
  44.  
  45. #define Op(x)        (x->op)
  46. #define Lit(x)        ((x->refs).lit)
  47. #define Child(x)    ((x->refs).child)
  48. #define Lchild(x)    ((x->refs).children.l_child)
  49. #define Rchild(x)    ((x->refs).children.r_child)
  50. #define Nullable(x)    (x->nullable)
  51. #define Firstpos(x)    (x->firstposn)
  52. #define Lastpos(x)    (x->lastposn)
  53.  
  54. /*************************************************************
  55.  *                                 *
  56.  *  Macros for manipulating DFA states and sets of states.   *
  57.  *                                 *
  58.  *************************************************************/
  59.  
  60. #define Positions(x)    (x->posns)
  61. #define Final_St(x)    (x->final)
  62. #define Goto(x, c)    ((x->trans)[c])
  63. #define Next_State(x)    ((x)->next_state)
  64.  
  65. /*************************************************************/
  66.  
  67. #define new_node(x)    malloc(sizeof(*x))
  68.  
  69. typedef struct {    /* character range literals */
  70.         char low_bd, hi_bd;
  71.     } *Ch_Range;
  72.  
  73. typedef struct ch_set {        /* character set literals */
  74.         Ch_Range elt;    /* rep. as list of ranges */
  75.         struct ch_set *rest;
  76.     } *Ch_Set;
  77.  
  78. typedef struct {    /* regular expression literal */
  79.         int pos;         /* position in syntax tree */
  80.         short l_type;    /* type of literal */
  81.         union {
  82.         char c;     /* for character literals */
  83.         Ch_Set cset; /* for character sets */
  84.         } val;
  85.     } *Re_Lit, *(*Re_lit_array)[];
  86.  
  87. typedef struct pnode {
  88.         int posnum;
  89.         struct pnode *nextpos;
  90.     } *Pset, *(*Pset_array)[];
  91.  
  92. typedef struct rnode {    /* regular expression node */
  93.         short op;     /* operator at that node */
  94.         union {
  95.         Re_Lit lit;        /* child is a leaf node */
  96.         struct rnode *child;    /* child of unary op */
  97.         struct {
  98.             struct rnode *l_child; 
  99.             struct rnode *r_child;
  100.         } children;        /* children of binary op */
  101.         } refs;
  102.         short nullable;
  103.         Pset firstposn, lastposn;
  104.     } *Re_node;
  105.  
  106. typedef struct {            /* token node */
  107.         short type;
  108.         Re_node val;
  109.     } *Tok_node;
  110.  
  111.  
  112. typedef struct snode {
  113.         Re_node val;
  114.         int size;
  115.         struct snode *next;
  116.     } *Stack;
  117.  
  118. typedef struct dfa_st {
  119.         Pset posns;
  120.         int final;        /* 1 if the state is a final state, 0 o/w */
  121.         struct dfa_st *trans[128];
  122.     } *Dfa_state;
  123.  
  124. typedef struct dfa_stset {
  125.         Dfa_state st;
  126.         struct dfa_stset *next_state;
  127.     } *Dfa_state_set;
  128.  
  129.  
  130.